package org.vectrics.struts;

import java.util.Iterator;
import java.util.List;

import org.vectrics.common.html.BorderTable;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Form;
import org.vectrics.common.html.Row;

public abstract class PageListTableTag extends PageListTag {

	private static final long serialVersionUID = -8808758875454328814L;

	public PageListTableTag() {
		super();
	}

	protected abstract String getTableWidth();
	protected abstract void renderHeaderRow(Row headerRow);
	protected abstract void renderDataRow(Row row, Object element);
	
	protected final void showList(String description, Cell mainCell, List elements, Form form) {
		BorderTable table = new BorderTable();
		table.setWidth(this.getTableWidth());
		mainCell.addElement(table);
		Row headerRow = table.addRow();
        headerRow.setDefaultBgImage(this.getContextPath() + "/site-graphics/tbl_hdr.gif");

		
		//headerRow.setDefaultCellFontClass("tableHdrFont");

		renderHeaderRow(headerRow);
		
		Iterator iter = elements.iterator();
		while (iter.hasNext()) {
			Object data = iter.next();
			Row row = table.addRow();
			row.setDefaultCellFontClass("subFont");
			renderDataRow(row, data);
		}
		
	}

}
